﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using ASPNETWebApplication.Repositories;
using ASPNETWebApplication.ActionServiceReference;

namespace ASPNETWebApplication.WebShop
{
    public partial class AddProduct : System.Web.UI.Page
    {
        /// <summary>
        /// Gets or sets the customerId for this page.
        /// </summary>
        private int CustomerId
        {
            get { return int.Parse(Session["CustomerId"].ToString()); }
            set { Session["CustomerId"] = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            var repository = new ProductRepository();

            ActionServiceReference.Product product;
            product = new ActionServiceReference.Product();
            
            //// Get Company name from page.
            //var row = DetailsViewCustomer.Rows[1];
            //var textBox = row.Cells[1].Controls[0] as TextBox;
            //customer.Company = textBox.Text.Trim();

            //// Get City from page.
            //row = DetailsViewCustomer.Rows[2];
            //textBox = row.Cells[1].Controls[0] as TextBox;
            //customer.City = textBox.Text.Trim();

            //// Get Country from page.
            //row = DetailsViewCustomer.Rows[3];
            //textBox = row.Cells[1].Controls[0] as TextBox;
            //customer.Country = textBox.Text.Trim();

            try
            {                
                repository.AddProduct(product);                
            }
            catch (ApplicationException ex)
            {
                //LabelError.Text = ex.Message.Replace(Environment.NewLine, "<br />");
                //PanelError.Visible = true;
                return;
            }

            // Return to list of customers.
            Response.Redirect(UrlMaker.ToProducts()); 
        }
    }
}